<template>
  <!-- <sidebar-top></sidebar-top> -->
  <div class="navbar clearfix">

    <!-- 左侧 菜单布局展示 折叠及面包屑 -->
    <template v-if="layoutType === 'leftMenuLayout'">
      <hamburger class="hamburger-container" :toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
      <!-- 当前系统内路由 - 展示当前系统面包屑 -->
      <template v-if="iframeHref === ''">
        <breadcrumb></breadcrumb>
      </template>
      <!-- 通过iframe加载三方系统 - 隐藏当前系统面包屑 -->
      <template v-else>
      </template>
    </template>

    <!-- 顶部 菜单布局展示 折叠及面包屑 -->
    <template v-if="layoutType === 'topMenuLayout'">
      <div class="pro-log">
        <img src="../../../../assets/images/login/logo-small.png" alt="">
        <!-- <span>{{ $t('layout.systemName') }}</span> -->
      </div>
      <top-horizontal-menu class="topMenu-container"></top-horizontal-menu>
    </template>

    <!-- 切换主题 -->
    <el-dropdown class="switch-theme-container avatar-container" trigger="click" v-if="multilTheme">
      <div class="avatar-wrapper">
        <span>切换主题</span>
        <el-icon><caret-bottom /></el-icon>
      </div>
      <template #dropdown>
        <el-dropdown-menu class="user-dropdown">
          <span v-for="(item, index) in sysThemeEnum" @click="handleToggleTheme(item.value)" :key="index">
            <el-dropdown-item>
              {{item.label}}
            </el-dropdown-item>
          </span>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <!-- 切换语言 -->
    <el-dropdown class="switch-lang-container avatar-container" trigger="click" v-if="multilLanguage">
      <div class="avatar-wrapper">
        <span>{{ $t('layout.switchLanguage') }}</span>
        <el-icon><caret-bottom /></el-icon>
      </div>
      <template #dropdown>
        <el-dropdown-menu class="user-dropdown">
          <span @click="handleToggleLang('zh-cn')">
            <el-dropdown-item>
              {{ $t('layout.zhCN') }}
            </el-dropdown-item>
          </span>
          <span @click="handleToggleLang('zh-tw')">
            <el-dropdown-item divided>
              <span style="display:block;">
                {{ $t('layout.zhTW') }}
              </span>
            </el-dropdown-item>
          </span>
          <span @click="handleToggleLang('en')">
            <el-dropdown-item divided>
              <span style="display:block;">
                {{ $t('layout.en') }}
              </span>
            </el-dropdown-item>
          </span>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <!-- 切换角色 -->
    <RoleSwitchDropDown></RoleSwitchDropDown>
    <!-- 用户操作列表 -->
    <el-dropdown class="avatar-container" trigger="click">
      <div class="avatar-wrapper">
        <img class="user-avatar" :src="avatar+'?imageView2/1/w/80/h/80'">
        <span>{{name}}</span>
        <el-icon><caret-bottom /></el-icon>
      </div>
      <!-- <div class="avatar-wrapper">
        <span>{{name}}</span>
        <el-icon><caret-bottom /></el-icon>
      </div> -->
      <template #dropdown>
        <el-dropdown-menu class="user-dropdown">
          <router-link class="inlineBlock" to="/">
            <el-dropdown-item>
              {{ $t('userDropdown.home') }}
            </el-dropdown-item>
          </router-link>
          <span @click="changePassword">
            <el-dropdown-item divided>
              <span style="display:block;">
                {{ $t('userDropdown.changePassword') }}
              </span>
            </el-dropdown-item>
          </span>
          <span @click="logout">
            <el-dropdown-item divided>
              <span style="display:block;">
                {{ $t('userDropdown.logout') }}
              </span>
            </el-dropdown-item>
          </span>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import TopHorizontalMenu from './Sidebar/TopHorizontalMenu'
import RoleSwitchDropDown from './RoleSwitch/DropDown.vue'
// import SidebarTop from './Sidebar/SidebarTop'
import { CaretBottom } from '@element-plus/icons-vue'

export default {
  components: {
    Breadcrumb,
    Hamburger,
    TopHorizontalMenu,
    RoleSwitchDropDown,
    CaretBottom
    // SidebarTop
  },
  computed: {
    ...mapGetters([
      'layoutType',
      'multilTheme',
      'multilLanguage',
      'sysThemeEnum',
      'name',
      'sidebar',
      'avatar',
      'iframeHref',
      'language'
    ])
  },
  inject: ['reloadRouter'],
  created() {
  },
  methods: {
    // 切换系统主题
    handleToggleTheme(val) {
      this.$store
        .dispatch('SetSysTheme', {
          theme: val
        }).then(theme => {
        })
    },
    // 切换语言
    handleToggleLang(lang) {
      this.$store
        .dispatch('SetLanguage', lang).then(lang => {
          this.reloadRouter()
        })
    },
    // 切换菜单折叠
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    // 退出登录
    logout() {
      this.$store.dispatch('LogOut').then(() => {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      })
    },
    // 修改密码
    changePassword() {
      this.$router.push({
        name: 'changePassword'
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.navbar {
  display: flex;
  flex-wrap: nowrap;
  height: 50px;
  line-height: 50px;
  border-radius: 0px !important;
  padding-right: 20px;
  background: #fff;
  .hamburger-container {
    line-height: 58px;
    height: 50px;
    padding: 0 10px;
  }
  .avatar-container {
    height: 50px;
    line-height: 50px;
    margin-left: 15px;
    .avatar-wrapper {
      cursor: pointer;
      // margin-top: 5px;
      position: relative;
      .user-avatar {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        vertical-align: middle;
        margin-right: 10px;
      }
      // .el-icon-caret-bottom {
      //   position: absolute;
      //   right: -20px;
      //   top: 25px;
      //   font-size: 12px;
      // }
    }
  }
  .switch-lang-container{
  }

  // 顶部导航
  .topMenu-container{
    flex: 1;
    border-bottom: transparent;
  }

}
</style>

